﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

namespace DefeatEpidemic.Migrations
{
    public partial class Init : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "Community",
                columns: table => new
                {
                    id = table.Column<Guid>(nullable: false),
                    name = table.Column<string>(nullable: true),
                    province = table.Column<string>(nullable: true),
                    city = table.Column<string>(nullable: true),
                    area = table.Column<string>(nullable: true),
                    detail = table.Column<string>(nullable: true),
                    created_at = table.Column<DateTime>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Community", x => x.id);
                });

            migrationBuilder.CreateTable(
                name: "Families",
                columns: table => new
                {
                    id = table.Column<Guid>(nullable: false),
                    name = table.Column<string>(nullable: true),
                    address = table.Column<string>(nullable: true),
                    status = table.Column<int>(nullable: false),
                    remark = table.Column<string>(nullable: true),
                    Created_at = table.Column<DateTime>(nullable: false),
                    Updated_at = table.Column<DateTime>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Families", x => x.id);
                });

            migrationBuilder.CreateTable(
                name: "Logs",
                columns: table => new
                {
                    id = table.Column<int>(nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    logDate = table.Column<DateTime>(nullable: false),
                    logLevel = table.Column<string>(nullable: true),
                    logType = table.Column<string>(nullable: true),
                    logger = table.Column<string>(nullable: true),
                    message = table.Column<string>(nullable: true),
                    machineName = table.Column<string>(nullable: true),
                    machineIp = table.Column<string>(nullable: true),
                    netRequestMethod = table.Column<string>(nullable: true),
                    netRequestUrl = table.Column<string>(nullable: true),
                    netUserIsauthenticated = table.Column<string>(nullable: true),
                    netUserAuthtype = table.Column<string>(nullable: true),
                    netUserIdentity = table.Column<string>(nullable: true),
                    exception = table.Column<string>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Logs", x => x.id);
                });

            migrationBuilder.CreateTable(
                name: "Records",
                columns: table => new
                {
                    id = table.Column<Guid>(nullable: false),
                    from = table.Column<string>(nullable: true),
                    to = table.Column<string>(nullable: true),
                    outdate = table.Column<DateTime>(nullable: false),
                    backdate = table.Column<DateTime>(nullable: false),
                    numberName = table.Column<string>(nullable: true),
                    idCard = table.Column<string>(nullable: true),
                    carNumber = table.Column<string>(nullable: true),
                    created_at = table.Column<DateTime>(nullable: false),
                    remark = table.Column<string>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Records", x => x.id);
                });

            migrationBuilder.CreateTable(
                name: "Members",
                columns: table => new
                {
                    id = table.Column<Guid>(nullable: false),
                    name = table.Column<string>(nullable: true),
                    idcard = table.Column<string>(nullable: true),
                    address = table.Column<string>(nullable: true),
                    mobile = table.Column<string>(nullable: true),
                    email = table.Column<string>(nullable: true),
                    companyName = table.Column<string>(nullable: true),
                    companyPlace = table.Column<string>(nullable: true),
                    created_at = table.Column<DateTime>(nullable: false),
                    updated_at = table.Column<DateTime>(nullable: false),
                    remark = table.Column<string>(nullable: true),
                    familyid = table.Column<Guid>(nullable: true),
                    communityid = table.Column<Guid>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Members", x => x.id);
                    table.ForeignKey(
                        name: "FK_Members_Community_communityid",
                        column: x => x.communityid,
                        principalTable: "Community",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_Members_Families_familyid",
                        column: x => x.familyid,
                        principalTable: "Families",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "Applications",
                columns: table => new
                {
                    id = table.Column<Guid>(nullable: false),
                    applicant = table.Column<string>(maxLength: 20, nullable: true),
                    from = table.Column<string>(maxLength: 50, nullable: true),
                    to = table.Column<string>(maxLength: 50, nullable: true),
                    connect = table.Column<string>(maxLength: 20, nullable: true),
                    isDirve = table.Column<int>(nullable: false),
                    carNumber = table.Column<string>(maxLength: 10, nullable: true),
                    outNumber = table.Column<int>(nullable: false),
                    status = table.Column<int>(nullable: false),
                    selfTemp = table.Column<float>(nullable: false),
                    measuredTemp = table.Column<float>(nullable: false),
                    reason = table.Column<string>(maxLength: 200, nullable: true),
                    remark = table.Column<string>(maxLength: 200, nullable: true),
                    outTime = table.Column<DateTime>(nullable: false),
                    created_at = table.Column<DateTime>(nullable: false),
                    memberid = table.Column<Guid>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Applications", x => x.id);
                    table.ForeignKey(
                        name: "FK_Applications_Members_memberid",
                        column: x => x.memberid,
                        principalTable: "Members",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "Cars",
                columns: table => new
                {
                    id = table.Column<Guid>(nullable: false),
                    brand = table.Column<string>(nullable: true),
                    color = table.Column<string>(nullable: true),
                    number = table.Column<string>(nullable: true),
                    created_at = table.Column<DateTime>(nullable: false),
                    updated_at = table.Column<DateTime>(nullable: false),
                    memberid = table.Column<Guid>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Cars", x => x.id);
                    table.ForeignKey(
                        name: "FK_Cars_Members_memberid",
                        column: x => x.memberid,
                        principalTable: "Members",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "Resources",
                columns: table => new
                {
                    id = table.Column<Guid>(nullable: false),
                    url = table.Column<string>(nullable: true),
                    path = table.Column<string>(nullable: true),
                    created_at = table.Column<DateTime>(nullable: false),
                    memberid = table.Column<Guid>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Resources", x => x.id);
                    table.ForeignKey(
                        name: "FK_Resources_Members_memberid",
                        column: x => x.memberid,
                        principalTable: "Members",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "Wxoauths",
                columns: table => new
                {
                    id = table.Column<Guid>(nullable: false),
                    oauth_name = table.Column<string>(maxLength: 30, nullable: true),
                    open_id = table.Column<string>(maxLength: 50, nullable: true),
                    unionid = table.Column<string>(maxLength: 50, nullable: true),
                    nick_name = table.Column<string>(maxLength: 50, nullable: true),
                    avatar = table.Column<string>(maxLength: 200, nullable: true),
                    mobile = table.Column<string>(maxLength: 20, nullable: true),
                    created_at = table.Column<DateTime>(nullable: false),
                    type = table.Column<int>(nullable: false),
                    lat = table.Column<double>(nullable: false),
                    lon = table.Column<double>(nullable: false),
                    accuracy = table.Column<double>(nullable: false),
                    memberid = table.Column<Guid>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Wxoauths", x => x.id);
                    table.ForeignKey(
                        name: "FK_Wxoauths_Members_memberid",
                        column: x => x.memberid,
                        principalTable: "Members",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateIndex(
                name: "IX_Applications_memberid",
                table: "Applications",
                column: "memberid");

            migrationBuilder.CreateIndex(
                name: "IX_Cars_memberid",
                table: "Cars",
                column: "memberid");

            migrationBuilder.CreateIndex(
                name: "IX_Members_communityid",
                table: "Members",
                column: "communityid");

            migrationBuilder.CreateIndex(
                name: "IX_Members_familyid",
                table: "Members",
                column: "familyid");

            migrationBuilder.CreateIndex(
                name: "IX_Resources_memberid",
                table: "Resources",
                column: "memberid");

            migrationBuilder.CreateIndex(
                name: "IX_Wxoauths_memberid",
                table: "Wxoauths",
                column: "memberid");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "Applications");

            migrationBuilder.DropTable(
                name: "Cars");

            migrationBuilder.DropTable(
                name: "Logs");

            migrationBuilder.DropTable(
                name: "Records");

            migrationBuilder.DropTable(
                name: "Resources");

            migrationBuilder.DropTable(
                name: "Wxoauths");

            migrationBuilder.DropTable(
                name: "Members");

            migrationBuilder.DropTable(
                name: "Community");

            migrationBuilder.DropTable(
                name: "Families");
        }
    }
}
